/*
 * CheckBoxMenuItemDelegate.h  0.4.0 / Dec 05, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef CHECKBOXMENUITEMDELEGATE_H
#define CHECKBOXMENUITEMDELEGATE_H

#include "Cute4jSwing.h"

#include "ActionComponentDelegate.h"

// CheckBoxMenuItemDelegate Class. ---------------------------------------------

/*!
 * \brief CheckBoxMenuItem Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT CheckBoxMenuItemDelegate : public ActionComponentDelegate
{
  Q_OBJECT
protected:
  CheckBoxMenuItemDelegate(JNIEnv *env, jobject obj);
public slots: // native calls
  void setText(JNIEnv *env, jstring text);
  void setShortcut(JNIEnv *env, jstring shortcut);
  void setIcon(JNIEnv *env, jobject iconSet);
  void setChecked(JNIEnv *env, jboolean checked);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls);
  static jlong newInstance(JNIEnv *env, jobject obj);
public: // native callbacks
  void checkedChanged(jint modifiers, jboolean checked);
protected slots:
  void toggledSlot(bool checked);
  void stateChangedSlot(int state);
protected:
  inline QCheckBox *checkBox() const;
protected:
  virtual QWidget *createQWidget();
  virtual QAction *createQAction();
  virtual void deleteQWidget(QWidget *widget);
  virtual void deleteQAction(QAction *action);
  virtual QWidget *convertToQWidget(QAction *action);
  virtual QAction *convertToQAction(QWidget *widget);
private:
  QShortcut *m_shortcut;
private:
  static jmethodID sm_checkedChangedMID;
};

// CheckBoxMenuItemDelegate :: Protected Inline Member Function. ---------------

/*!
 * \brief Returns check box member.
 *
 * \return check box member
 */
inline QCheckBox *CheckBoxMenuItemDelegate::checkBox() const
{
  return static_cast<QCheckBox *>(widget());
}

// Macro Definition. -----------------------------------------------------------

#define CHECK_BOX_MENU_ITEM_DELEGATE \
    (reinterpret_cast<CheckBoxMenuItemDelegate *>(delegate))

#endif // CHECKBOXMENUITEMDELEGATE_H
